<template>
  <el-dialog :visible.sync="dialog" append-to-body title="执行日志" width="88%">
    <!-- 搜索 -->
    <div class="head-container">
      <el-input v-model="params.jobName" clearable placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
      <el-select v-model="isSuccess" placeholder="日志状态" clearable class="filter-item" style="width: 110px" @change="toQuery">
        <el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button size="mini" type="primary" icon="el-icon-search" @click="toQuery">搜索</el-button>
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" :height="tableHeight" fit border size="mini" tyle="width: 100%;">
      <el-table-column show-overflow-tooltip prop="jobName" header-align="center" width="150px" label="任务名称"/>
      <el-table-column show-overflow-tooltip prop="beanName" header-align="center" width="200px" label="Bean名称"/>
      <el-table-column show-overflow-tooltip prop="methodName" align="center" width="80px" label="执行方法"/>
      <el-table-column show-overflow-tooltip prop="params" header-align="center" label="参数"/>
      <el-table-column prop="data" label="传输数据" width="80px" align="center" >
        <template slot-scope="scope">
          <el-button v-show="scope.row.data" size="mini" type="text" @click="info(scope.row.data)">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="exceptionDetail" label="异常详情" width="80px" align="center" >
        <template slot-scope="scope">
          <el-button v-show="scope.row.exceptionDetail" size="mini" type="text" @click="info(scope.row.exceptionDetail)">查看详情</el-button>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip align="center" width="100px" prop="time" label="耗时(毫秒)"/>
      <el-table-column align="center" prop="isSuccess" width="60px" label="状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.isSuccess ? 'success' : 'danger'">{{ scope.row.isSuccess ? '成功' : '失败' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="crtTime" width="150px" align="center" label="创建日期">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.crtTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="errorDialog" append-to-body title="详情" width="85%">
      <span>
        {{ errorInfo }}
      </span>
    </el-dialog>
    <!--分页组件-->
    <el-pagination  :total="total" :page-size="20" style="margin-top:8px;" layout="total, prev, pager, next"
      @size-change="sizeChange" @current-change="pageChange"/>
  </el-dialog>
</template>

<script>
import checkPermission from '@/utils/permission'
import tableHeight from '@/mixins/tableHeight'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
export default {
  mixins: [initData, tableHeight],
  data () {
    return {
      errorInfo: '',
      errorDialog: false,
      dialog: false,
      isSuccess: undefined,
      enabledTypeOptions: [
        { key: 'true', display_name: '成功' },
        { key: 'false', display_name: '失败' }
      ]
    }
  },
  methods: {
    parseTime,
    checkPermission,
    doInit () {
      this.$nextTick(() => {
        this.init()
      })
    },
    toQuery () {
      this.page = 0
      this.doInit()
    },
    beforeInit () {
      this.url = 'api/quartz/job/pageLog'
      if (this.isSuccess) { this.params.isSuccess = this.isSuccess }
      return true
    },
    info (errorInfo) {
      this.errorInfo = errorInfo
      this.errorDialog = true
    }
  }
}
</script>
